﻿

Imports System.Object
Imports VSModel
Imports Cls_Common
Imports System.IO
Imports System.Data
Partial Class FrontEnd_Control_Home_HotProductStoreVip
    Inherits System.Web.UI.UserControl

#Region "Sub and function"
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            LoadData()
        End If
    End Sub
    Private Sub LoadData()
        Using Data As New VSEntities
            Dim p = (From q In Data.Products
                     Where q.Store.IsVip = True And q.StatusId = 3 And q.PublishedDate <= Now() And (q.eEffectiveDate >= Now() Or q.eEffectiveDate Is Nothing)
                     Order By q.PublishedDate Descending Select New With {q.ProductId, q.Title, q.Description, q.QueryString, q.ImagePreview, q.SellPrice, q.OriginalPrice, .CateQuerystring = q.Category.QueryString, q.CateID}).Take(1).ToList
            rptShow.DataSource = p
            rptShow.DataBind()

        End Using
    End Sub
#End Region
#Region "Event for control"
    Protected Sub rptShow_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptShow.ItemDataBound
        Dim row = CType(e.Item.DataItem, Object)
        Dim img As Image = CType(e.Item.FindControl("img"), Image)
        Dim hplTitle As HyperLink = CType(e.Item.FindControl("hplTitle"), HyperLink)
        'Dim hplImg As HyperLink = CType(e.Item.FindControl("hplImg"), HyperLink)
        Dim ltrPrice As Literal = CType(e.Item.FindControl("ltrPrice"), Literal)

        img.ImageUrl = CookedImageURL("140-120", row.ImagePreview)
        img.AlternateText = row.Title
        img.Style.Add("overflow", "hidden")
        hplTitle.Text = row.Title
        'hplImg.NavigateUrl = MainDomain & row.CateQuerystring & "-" & row.CateID.ToString & "/" & row.QueryString & "-" & row.ProductId.ToString & "/chi-tiet.html"
        hplTitle.NavigateUrl = MainDomain & row.QueryString & "-" & row.ProductId.ToString & ".html"

        ltrPrice.Text = Format_Currency(row.OriginalPrice.ToString())
    End Sub
#End Region
End Class
